var express = require('express');
var path = require('path');
var router = express.Router();
//=======第一步=========
var query = require('./pool');
var bodyParser = require('body-parser');
var urlEncoded = bodyParser.urlencoded({extended: false});

//======================
router.get('/', function (req, res) {
    let pathStr = path.normalize(__dirname + '\/../views/lbwxq.html');
    res.sendFile(pathStr);
});
//=======第二步=========
router.post('/pl',urlEncoded,async (req, res) => {
    // console.log(req.body);
    let rows = await query('select * from shopcomment where source=' + req.body.id + '');
    let lemons = await query('select * from shop_details where sp_id =' + req.body.sp_id + '');
    let goods = await query('select * from goods where goods_id =' + req.body.goods_id + '');
    let goodsName = await query('select * from goods where goods_name ="' + req.body.goods_name + '"');
    if (rows.length > 0) {
        let json = {
            code: '1',
            result: rows,
            res: lemons,
            resu: goods,
            resul: goodsName
        };
        res.send(json);
    }else {
        let json = {
            code: '0'
        };
        res.send(json);
    }
    // console.log('ggggggggggggggggggggggggg');
    // console.log(rows, lemons,goods,goodName);
});



// 商品详情

router.post('/zk', urlEncoded, async (req, res) => {
    // console.log('wwwwwwwwwwwwwwwwwwwwww');
    console.log(req.body, '==================');
    if (req.body) {
        let sql = 'insert into sp_car set ?';
        let car = await query(sql, req.body, (error, results, fields) => {
            if (error) throw error;
        });
        let json = {
            code: '100',
            cara: car
        };
        res.send(json);
    } else {
        let json = {
            code: 0
        };
        res.send(json);
    }
});

module.exports = router;


